import axios from "../assets/encrypt/assetsRequest.js";
let params = {
  url: "/assets/assetsLogin.do",
  method: "post",
  data: {
    employeeNo: "heiheihei"
    // employeeNo: "01007119"
  },
  transformRequest: function(data) {
    data = JSON.stringify(data);

    return data;
  }
};
export function assetsLogin() {
  return axios(params);
}

export const assetsList = data => {
  return axios(
    // "http://192.168.1.146:9200/api-assetsBusiness/assetsTodoList/getTodoList?isFromNtalk=1",
    "http://192.168.10.92:9200/api-assetsBusiness/assetsTodoList/getTodoList?isFromNtalk=1",
    { params: data }
  );
};

export const toExamine = (name, data, actName) => {
  let url = "";
  if (name == "报废流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/scrap/taskList";
  } else if (name == "采购确认流程") {
    url =
      "http://192.168.10.92:9200/api-assetsBusiness/process/listHistory/" +
      data.instanceId +
      "?access_token=" +
      data.access_token;
  } else if (name == "借用流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/borrow/taskList";
  } else if (name == "调拨流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/transfer/taskList";
  } else if (name == "固定资产申购流程") {
    if (actName == "采购受理") {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/purchase/acceptanceProcurement?page=1&limit=10&pageFlag=0&gmAssetsType=1";
    } else {
      url = "http://192.168.10.92:9200/api-assetsBusiness/purchase/taskList";
    }
  } else if (name == "低值易耗申购流程") {
    if (actName == "采购受理") {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/purchase/acceptanceProcurement?page=1&limit=10&pageFlag=1&gmAssetsType=1";
    } else {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/purchase/taskList/taskConsumableList";
    }
  } else if (name == "低值易耗申领流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/claimants/taskList";
  } else if (name == "退货流程") {
    url =
      "http://192.168.10.92:9200/api-assetsBusiness/warehouseOutManageController/getReturnGoodsTodoList";
  } else if (name == "补货申请流程") {
    if (actName == "采购受理") {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/warehouseManage/procurement?page=1&limit=10&pageFlag=0&gmAssetsType=1";
    } else {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/warehouseManage/taskList";
    }
  }

  console.log(url, data, 42);

  // if (name == "采购确认流程") {
  //   // return Promise.resolve("采购确认流程");
  //   console.log("采购");

  //   return axios(url);
  // }

  if (name == "退货流程") {
    return axios({
      url,
      method: "post",
      params: data,
      data,
      transformRequest: function(data, headers) {
        // 对发送的 data 进行任意转换处理
        console.log(data, 70);
        return JSON.stringify(data);
      }
    });
  }

  // if (actName == "采购受理") {
  //   console.log("采购");
  //   return axios(url);
  // }

  console.log("非采购");
  return axios(url, { params: data });
};
//  http://192.168.10.92:9200/api-assetsBusiness/warehouseOutManageController/returnGoodscomplete/
export const process = (name, actName, id, data) => {
  //  http://192.168.10.92:9200/api-assetsBusiness/purchase/complete/{taskId}
  let url = "";
  if (name == "报废流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/scrap/complete/" + id;
  } else if (name == "借用流程") {
    url = "http://192.168.10.92:9200/api-assetsBusiness/borrow/complete/" + id;
  } else if (name == "调拨流程") {
    url =
      "http://192.168.10.92:9200/api-assetsBusiness/transfer/complete/" + id;
  } else if (name == "固定资产申购流程") {
    if (actName == "采购受理") {
      url = "http://192.168.10.92:9200/api-assetsBusiness/purchase/save";
    } else {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/purchase/complete/" + id;
    }
  } else if (name == "低值易耗申购流程") {
    if (actName == "采购受理") {
      url = "http://192.168.10.92:9200/api-assetsBusiness/apply/save";
    } else {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/purchase/consumable/complete/" +
        id;
    }
  } else if (name == "低值易耗申领流程") {
    url =
      "http://192.168.10.92:9200/api-assetsBusiness/claimants/completeT/" + id;
  } else if (name == "退货流程") {
    url =
      "http://192.168.10.92:9200/api-assetsBusiness/warehouseOutManageController/returnGoodscomplete/";
  } else if (name == "补货申请流程") {
    if (actName == "采购受理") {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/warehouseManage/submit";
    } else {
      url =
        "http://192.168.10.92:9200/api-assetsBusiness/warehouseManage/complete/" +
        id;
    }
  }

  if (url) {
    return axios({
      method: "post",
      url,
      data,
      headers: {
        Authorization: "bearer " + localStorage.getItem("accessToken")
      },
      transformRequest: function(data, headers) {
        // 对发送的 data 进行任意转换处理

        return JSON.stringify(data);
      }
    });
  } else {
    return Promise.reject("请求失败");
  }
};
// ?access_token=b6e7263a-836f-4301-ba6d-e466c6275db5
export const getTree = params => {
  return axios(
    "http://192.168.10.92:9200/api-assetsBusiness/beginningRegistration/getDeptTree",
    { params }
  );
};

// http://192.168.10.92:9200/api-assetsBusiness/apply/exportGoods/1725?access_token=ac2d350b-0cae-45f8-970c-7428019aa754

export const exportGoods = (id, access_token) => {
  return axios.post(
    `http://192.168.10.92:9200/api-assetsBusiness/apply/exportGoods/${id}?access_token=${access_token}`,
    {}
    // { responseType: "blob" }
  );
};

//  http://192.168.10.92:9200/api-file/files/downloadFile/efe379ecdbba22150a80309984f376a6?access_token=ac2d350b-0cae-45f8-970c-7428019aa754

export const downloadFile = (id, access_token) => {
  return axios(
    `http://192.168.10.92:9200/api-file/files/downloadFile/${id}?access_token=${access_token}`,
    { responseType: "blob" }
  );
};

// http://192.168.10.92:9200/api-file/files/ioReadFile/

export const ioReadFile = (id, access_token) => {
  return axios(
    `http://192.168.10.92:9200/api-file/files/ioReadFile/${id}?access_token=${access_token}`,
    { responseType: "blob" }
  );
};

//  http://192.168.10.92:9200/api-assetsBusiness/process/listHistory/3455177?page=1&limit=10&access_token=ea76b100-1ea5-48ee-a231-df200d794aa1

export const listHistory = (accessToken, taskId) => {
  let params = {
    page: 1,
    limit: 10
  };
  console.log(taskId, 164);
  return axios(
    "http://192.168.10.92:9200/api-assetsBusiness/process/listHistory/" +
      taskId,
    { params: { ...params, ...accessToken } }
  );
};

//  http://192.168.10.92:9200/api-assetsBusiness/warehouseOutManageController/getReturnGoodsDataTodoList

export const getReturnGoodsDataTodoList = data => {
  return axios({
    url:
      "http://192.168.10.92:9200/api-assetsBusiness/warehouseOutManageController/getReturnGoodsDataTodoList",
    method: "post",
    data,
    headers: {
      Authorization: "bearer " + localStorage.getItem("accessToken")
    },
    transformRequest: function(data, headers) {
      // 对发送的 data 进行任意转换处理

      return JSON.stringify(data);
    }
  });
};

// http://192.168.10.92:9200/api-assetsBusiness/customerManageController/getCustomerName?access_token=a21f00be-f0e8-4ab0-8e92-128eb3176e10
export const getCustomerName = () => {
  return axios(
    `http://192.168.10.92:9200/api-assetsBusiness/customerManageController/getCustomerName?access_token=${localStorage.getItem(
      "accessToken"
    )}`
  );
};
